import { ref } from 'vue'
import { NetworkTypeOptional } from './types'
import { networkTypePageSelect } from '@/api/network'

const useNetworkTypeOptions = () => {
  const getNetworkTypeOptionsLoading = ref(false)
  const networkTypeOptions = ref<Array<NetworkTypeOptional>>([])

  const getNetworkTypeOptions = async (keyword: string) => {
    getNetworkTypeOptionsLoading.value = true
    const res = await networkTypePageSelect({ limit: 0, page: 0, name: keyword })
    networkTypeOptions.value = res.data.success ? res.data.data.rows : []
    getNetworkTypeOptionsLoading.value = false
  }

  const clearNetworkTypeOptions = () => {
    networkTypeOptions.value = []
  }

  return {
    networkTypeOptions,
    getNetworkTypeOptionsLoading,
    getNetworkTypeOptions,
    clearNetworkTypeOptions,
  }
}

export default useNetworkTypeOptions
